package org.graduates.webapp.actions.course.json;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.graduates.webapp.actions.BaseAction;
import org.projects.graduates.domain.Course;
import org.projects.graduates.domain.TimeTable;

import com.opensymphony.xwork2.ActionSupport;

/**
 * 获取课程的课程表
 * 
 * @author Administrator
 * 
 */
@ParentPackage("web")
public class GetTimetableAction extends BaseAction {

	private static final long serialVersionUID = -6914090137038393200L;

	private long cid = 0L;

	private List<TimeTable> tts = new ArrayList<TimeTable>();

	private TimeTable today;

	@Action(results = { @Result(name = "success", type = "json", params = {
			"includeProperties",
			"tts\\[\\d+\\]\\.course, tts\\[\\d+\\]\\.course.id, tts\\[\\d+\\]\\.content,tts\\[\\d+\\]\\.content.title, tts\\[\\d+\\]\\.id, tts\\[\\d+\\]\\.teachDate, tts\\[\\d+\\]\\.status,"
		+ "today, today.id, today.content, today.content.title, today.content.txt, today.course, today.course.id" }) })
	public String execute() {

		if (0L == cid) {
			return ActionSupport.INPUT;
		}

		Course course = Course.get(Course.class, cid);

		tts.addAll(TimeTable.findBy(course));

		today = TimeTable.getToday(course);

		return ActionSupport.SUCCESS;
	}

	public long getCid() {
		return cid;
	}

	public void setCid(long cid) {
		this.cid = cid;
	}

	public List<TimeTable> getTts() {
		return tts;
	}

	public void setTts(List<TimeTable> tts) {
		this.tts = tts;
	}

	public TimeTable getToday() {
		return today;
	}

	public void setToday(TimeTable today) {
		this.today = today;
	}

}
